package com.yyds.controller;

import com.aliyuncs.ram.model.v20150501.GetUserResponse;
import com.yyds.common.MyJSON;
import com.yyds.common.R;
import com.yyds.pojo.UserAdmin;
import com.yyds.service.UserAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/useradmin")
public class UserAdminController {

    @Autowired
    private UserAdminService userAdminService;

    @PostMapping("login")
    public R login(@RequestParam("admin_name") String admin_name,@RequestParam("admin_password") String admin_password){
        //返回从前端传过来的账号和密码
        return userAdminService.login(admin_name, admin_password);
    }

    /**
     *
     * @param page 页数
     * @param limit 每页的数据条数
     * @param userAdmin 用来接前端的模糊查询条件
     * @return
     */
    @RequestMapping("/list")
    public MyJSON<UserAdmin> list(UserAdmin userAdmin,int page,int limit){
        return userAdminService.selectAllUserAdminService(page,limit,userAdmin);
    }

    @RequestMapping("/del")
    public R del(UserAdmin userAdmin){

        return userAdminService.deleteAdminService(userAdmin);
    }

    @RequestMapping("/add")
    public R add(UserAdmin userAdmin){

        return userAdminService.addAdminService(userAdmin);
    }

    @RequestMapping("update")
    public R update(UserAdmin userAdmin){
        return userAdminService.updateAdminService(userAdmin);
    }
}
